<!--


calDateFormat    = "MM/DD/yyyy" //
// CALENDAR COLORS
topBackground    = "white";							// BG COLOR OF THE TOP FRAME
bottomBackground = "white";							// BG COLOR OF THE BOTTOM FRAME
tableBGColor     = "#244E75";							// BG COLOR OF THE BOTTOM FRAME'S TABLE
cellColor        = "#B5C9DB";						// TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
headingCellColor = "#244E75";							// TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
headingTextColor = "#FFFFFF";							// TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
dateColor        = "#000000";							// TEXT COLOR OF THE LISTED DATES (1-28+)
focusColor       = "#ff0000";						// TEXT COLOR OF THE SELECTED DATE (OR CURRENT DATE)
hoverColor       = "#ff0000";						// TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
fontStyle        = "9pt arial, helvetica";          // TEXT STYLE FOR DATES
headingFontStyle = "bold 9pt arial, helvetica";     // TEXT STYLE FOR WEEKDAY ABBREVIATIONS

fontStyleSelected = "9pt arial, helvetica";
bottomBorder  = false;								// TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
tableBorder   = 0;									// SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none

// END USER-EDITABLE SECTION -------------------------------------------------------


// DETERMINE BROWSER BRAND
var isNav = false;
var isIE  = false;

var MyDateField="";
var sControlName="";
var sFormName="";
var sLayerName="";
var sDateString="";
var inDate;
var ClickedDay = 1;
// ASSUME ITS EITHER NETSCAPE OR MSIE
if (navigator.appName == "Netscape") {
    isNav = true;
}
else {
    isIE = true;
}

// GET CURRENTLY SELECTED LANGUAGE
selectedLanguage = navigator.language;

// PRE-BUILD PORTIONS OF THE CALENDAR WHEN THIS JS LIBRARY LOADS INTO THE BROWSER
buildCalParts();


// SET THE INITIAL VALUE OF THE GLOBAL DATE FIELD
function setDateField(sCntName,sFmName,sLyName) {

    // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
    sControlName = sCntName;
	sFormName = sFmName;
	sLayerName = sLyName;
	var oTempObject;
		
	// GET THE VALUE OF THE INCOMING FIELD
	if((isIE)||((isNav)&&(!(sLayerName)))){
		oObject = eval("document." + sFormName + "." + sControlName );
		calDateField = oObject.value;
		inDate = oObject.value;
	}	
	if((isNav)&&(!(sLayerName)==false)){
		oObject = eval("document."+ sLayerName + ".document." + sFormName + "." + sControlName);
		calDateField = oObject.value;
		inDate = oObject.value;
	}	
					
    // SET calDate TO THE DATE IN THE INCOMING FIELD OR DEFAULT TO TODAYS DATE
    setInitialDate();

    // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
    calDocTop    = buildTopCalFrame();
    calDocBottom = buildBottomCalFrame();
}


// SET THE INITIAL CALENDAR DATE TO TODAY OR TO THE EXISTING VALUE IN dateField
function setInitialDate() {
   
    // CREATE A NEW DATE OBJECT (WILL GENERALLY PARSE CORRECT DATE EXCEPT WHEN "." IS USED AS A DELIMITER)
    // (THIS ROUTINE DOES *NOT* CATCH ALL DATE FORMATS, IF YOU NEED TO PARSE A CUSTOM DATE FORMAT, DO IT HERE)
    calDate = new Date(inDate);

    // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
    if (isNaN(calDate)) {

        // ADD CUSTOM DATE PARSING HERE
        // IF IT FAILS, SIMPLY CREATE A NEW DATE OBJECT WHICH DEFAULTS TO THE CURRENT DATE
        calDate = new Date();
    }

    // KEEP TRACK OF THE CURRENT DAY VALUE
    calDay  = calDate.getDate();
	ClickedDay = calDay;

}


// POPUP A WINDOW WITH THE CALENDAR IN IT
function showCalendar(dateField) {

    // SET INITIAL VALUE OF THE DATE FIELD AND CREATE TOP AND BOTTOM FRAMES
    setDateField(dateField);

    // USE THE JAVASCRIPT-GENERATED DOCUMENTS (calDocTop, calDocBottom) IN THE FRAMESET
	
	calDocFrameset = 
        "<HTML><HEAD><TITLE>Total Billings - Calendar</TITLE></HEAD>\n" +
        "<FRAMESET ROWS='65,*' FRAMEBORDER='0' FRAMESCPING='0' BORDER='0'>\n" +
        "  <FRAME NAME='topCalFrame' SRC='javascript:parent.opener.calDocTop' SCROLLING='no' NORESIZE frameborder='0' framespacing='0'>\n" +
        "  <FRAME NAME='bottomCalFrame' SRC='javascript:parent.opener.calDocBottom' SCROLLING='no' NORESIZE frameborder='0' framespacing='0'>\n" +
        "</FRAMESET>\n";

    // DISPLAY THE CALENDAR IN A NEW POPUP WINDOW
    top.newWin = window.open("javascript:parent.opener.calDocFrameset", "calWin", winPrefs);
    top.newWin.focus();
}


// CREATE THE TOP CALENDAR FRAME
function buildTopCalFrame() {

	// -- NILANTHAJ AMMENDED THIS FUNCTION ON 16-FEB-2001
	//    TO ENCANCE FEATURES.--
	// CREATE THE TOP FRAME OF THE CALENDAR
    var calDoc =
        "<HTML>" +
        "<HEAD>" +
		"</HEAD>" +
        "<SCR" + "IPT LANGUAGE=javascript>\n" +
        "<!-- \n" +        
        " var bCheck = '';\n" + 
        "function isNumber(InputValue) {\n" +	
		"	var numStr='0123456789';\n" +
		"	var thisChar;\n" +	
		"	var counter = 0;\n" +	
		"	var bool=true;\n" +	
		"	var TypedYear='';\n" +	
		"	for (var i=0; i < InputValue.length; i++) { \n" +	
		"		thisChar = InputValue.substring(i, i+1);\n" +	
		"		if (numStr.indexOf(thisChar) != -1)\n" +	
		"			counter ++;\n" +	
		"	}\n" +	
		"	if (counter == InputValue.length) {\n" +	
		"	// All characters are numbers \n" +	
		"		bool=true;\n" +	
		"	}else{\n" +	
		"		bool=false;\n" +	
		"	}\n" +	
		"	return(bool);\n" +	
		"}\n" +	    
        "function OnEnterKeyUp(e) {\n" +
        "	numYear = new Number();\n" +
        "	var TypedYear = document.calControl.year.value;\n" +
        "	numYear = TypedYear;\n" +
		"if (navigator.appName == 'Netscape') {\n" +
		"	if (e.which == '13') {\n" + 
		"		if (!(isNaN(TypedYear)) && (TypedYear.length ==4) && (isNumber(TypedYear) == true) && (numYear.valueOf()>= 1000)) {\n" +
		"			document.calControl.year.value = TypedYear;\n" +
		"			parent.opener.selectDate();\n" +
		"		}else {\n" +
		"			alert('Please enter a valid 4 digit year.');\n" +
		"			parent.bottomCalFrame.document.frmBotcalControl.Cancel.focus();\n" +
		"			return false;" +
		"		}\n" +		
		"	}else if (TypedYear.length == 4){\n" +
		"		if (bCheck != 'Y'){\n" +
		"			bCheck = 'Y';\n" +
		"			parent.opener.Refresh();\n" +
		"		}\n" + 
		"	}else if (TypedYear.length != 4){\n" +
		"			bCheck = '';\n"	+
		"	}\n" + 
		"}else{\n" +
		"	if (event.keyCode == '13') {\n" +
		"		if (!(isNaN(TypedYear)) && (TypedYear.length ==4) && (isNumber(TypedYear) == true) && (numYear.valueOf()>= 1000)) {\n" +
		"			document.calControl.year.value = TypedYear;\n" +
		"			parent.opener.selectDate();\n" +
		"		}else {\n" +
		"			alert('Please enter a valid 4 digit year.');\n" +
		"			parent.bottomCalFrame.document.frmBotcalControl.Cancel.focus();\n" +
		"			return false;" +
		"		}\n" +
		"	}else if (TypedYear.length == 4){\n" +
		"		if (bCheck != 'Y'){\n" +
		"			bCheck = 'Y';\n" +
		"			parent.opener.Refresh();\n" +
		"		}\n" + 
		"	}else if (TypedYear.length != 4){\n" +
		"			bCheck = '';\n"	+
		"	}\n" + 
		"}}\n" +
		"if (navigator.appName == 'Netscape') {\n" +
		"	document.captureEvents(Event.KEYUP);\n" +
		"}\n"+
		"	document.onkeyup=OnEnterKeyUp;\n" +
		"//-->\n" +	
		"</SC" + "RIPT>\n" +
        "<BODY BGCOLOR='" + topBackground + "' topmargin='7' bottommargin='0'>" +
        "<FORM NAME='calControl' onSubmit='return false;'>" +
        "<CENTER>" +
        "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0>" +
        "<TR><TD>" +
        "<CENTER>" +
        getMonthSelect() +
        "&nbsp;&nbsp;"+
		"<INPUT NAME='year' VALUE='" + calDate.getFullYear() + "'TYPE=TEXT SIZE=4 MAXLENGTH=4 onChange='parent.opener.setYear()' >" +   
        "</CENTER>" +
        "</TD>" +
        "</TR>" +
        "<TR>" +
        "<TD>" +
        "<INPUT " +
        "TYPE=BUTTON NAME='previousYear' VALUE='<<'    onClick='parent.opener.setPreviousYear()'><INPUT " +
        "TYPE=BUTTON NAME='previousMonth' VALUE=' < '   onClick='parent.opener.setPreviousMonth()'><INPUT " +
        "TYPE=BUTTON NAME='today' VALUE='Today' onClick='parent.opener.setToday()'><INPUT " +
        "TYPE=BUTTON NAME='nextMonth' VALUE=' > '   onClick='parent.opener.setNextMonth()'><INPUT " +
        "TYPE=BUTTON NAME='nextYear' VALUE='>>'    onClick='parent.opener.setNextYear()'>" +
        "</TD>" +
        "</TR>" +
        "</TABLE>" +
        "</CENTER>" +
        "</FORM>" +
        "</BODY>" +
        "</HTML>";
	
    return calDoc;
}


// CREATE THE BOTTOM CALENDAR FRAME 
// (THE MONTHLY CALENDAR)
function buildBottomCalFrame() {       

    // START CALENDAR DOCUMENT
    var calDoc = calendarBegin;
	
    // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
    month   = calDate.getMonth();
    year    = calDate.getFullYear();
	calDay=calDate.getDate();

    // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
    day     = calDay;

    var i   = 0;

    // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
    var days = getDaysInMonth();

    // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
    if (day > days) {
        day = days;
    }

    // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
    var firstOfMonth = new Date (year, month, 1);

    // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
    var startingPos  = firstOfMonth.getDay();
    days += startingPos;

    // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
    var columnCount = 0;

    // MAKE BEGINNING NON-DATE CELLS BLANK
    for (i = 0; i < startingPos; i++) {

        calDoc += blankCell;
	columnCount++;
    }

    // SET VALUES FOR DAYS OF THE MONTH
    var currentDay = 0;
    var dayType    = "weekday";

    // DATE CELLS CONTAIN A NUMBER
    for (i = startingPos; i < days; i++) {

	var paddingChar = "&nbsp;";

        // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
        if (i-startingPos+1 < 10) {
            padding = "&nbsp;&nbsp;";
        }
        else {
            padding = "&nbsp;";
        }

        // GET THE DAY CURRENTLY BEING WRITTEN
        currentDay = i-startingPos+1;

        // SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
        if (currentDay == day) {
            dayType = "focusDay";
        }
        else {
            dayType = "weekDay";
        }

        // ADD THE DAY TO THE CALENDAR STRING
        calDoc += "<TD align=center bgcolor='" + cellColor + "'>" +
                  "<a class='" + dayType + "' href='javascript:parent.opener.returnDate(" + 
                  currentDay + ")'>" + padding + currentDay + paddingChar + "</a></TD>";

        columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR><TR>";
        }
    }

    // MAKE REMAINING NON-DATE CELLS BLANK
    for (i=days; i<42; i++)  {

        calDoc += blankCell;
	columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR>";
            if (i<41) {
                calDoc += "<TR>";
            }
        }
    }

    // FINISH THE NEW CALENDAR PAGE
    calDoc += calendarEnd;



    // RETURN THE COMPLETED CALENDAR PAGE
    return calDoc;
}


// WRITE THE MONTHLY CALENDAR TO THE BOTTOM CALENDAR FRAME
function writeCalendar() {
	
    // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
    calDocBottom = buildBottomCalFrame();
    
    // WRITE THE NEW CALENDAR TO THE BOTTOM FRAME
    top.newWin.frames['bottomCalFrame'].document.open();
    top.newWin.frames['bottomCalFrame'].document.write(calDocBottom);
    top.newWin.frames['bottomCalFrame'].document.close();
           
}


// SET THE CALENDAR TO TODAYS DATE AND DISPLAY THE NEW CALENDAR
function setToday() {

    // SET GLOBAL DATE TO TODAY'S DATE
    calDate = new Date();
    
    // INITIALIZE GLOBAL VARIABLE	
    MyDateField = "";

    // SET DAY MONTH AND YEAR TO TODAYS DATE
    var month = calDate.getMonth();
    var year  = calDate.getFullYear();

    // SET MONTH IN DROP-DOWN LIST
    top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;

    // SET YEAR VALUE
    top.newWin.frames['topCalFrame'].document.calControl.year.value = year;

    // DISPLAY THE NEW CALENDAR
    writeCalendar();
}

// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
function Refresh(){

var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
	
	if (!(isNaN(year)) && (year.length==4) && (isNumber(year) == true)){
		calDate.setFullYear(year);
		writeCalendar();
	}
}

	// ADD NEW VALIDATION CHECK BY NILANTHAJ ON 16-FEB-2001
	// VALIDATE THE NEWLY ENTERED YEAR BEFORE REDRAW THE CALENDAR
function isNumber(InputValue) 
{	
	var numStr="0123456789";
	var thisChar;
	var counter = 0;
	var bool=true;
	for (var i=0; i < InputValue.length; i++)  
	{
		thisChar = InputValue.substring(i, i+1);
		if (numStr.indexOf(thisChar) != -1)
			counter ++;
	}
	if (counter == InputValue.length) 
	{	// All characters are numbers
		bool=true;
	}
	else 
	{
		bool=false;
	}
	return(bool);
}

// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
function setYear() {
/*
    // GET THE NEW YEAR VALUE 
    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
	
	// ADD NEW VALIDATION CHECK BY NILANTHAJ ON - FEB -  2001
	if (isNaN(year)) {
		window.alert("Please enter a valid 4 digit year.");
		top.newWin.frames['topCalFrame'].document.calControl.year.select();
		top.newWin.frames['topCalFrame'].document.calControl.year.focus();
		return false;
	}
	
	else top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
		

   // IF ITS A FOUR-DIGIT YEAR THEN CHANGE THE CALENDAR
    if (isFourDigitYear(year)) {
        calDate.setFullYear(year);
        writeCalendar();
    }
    else {
        // HIGHLIGHT THE YEAR IF THE YEAR IS NOT FOUR DIGITS IN LENGTH
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
    }*/
}


// SET THE GLOBAL DATE TO THE SELECTED MONTH AND REDRAW THE CALENDAR
function setCurrentMonth() {

    // GET THE NEWLY SELECTED MONTH AND CHANGE THE CALENDAR ACCORDINGLY
    var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

	calDate.setDate(1);
    calDate.setMonth(month);
	// {Upendra 20/sep/2001
		var mdaysInMonth = getDaysInMonth()
		if(ClickedDay > mdaysInMonth)
			{ 
				calDate.setDate(mdaysInMonth);
				returnRelativeDate(mdaysInMonth)
			}
		else
			{	
				calDate.setDate(ClickedDay);
				returnRelativeDate(ClickedDay)
			}
		//Upendra}	

    writeCalendar();
}


// SET THE GLOBAL DATE TO THE PREVIOUS YEAR AND REDRAW THE CALENDAR
function setPreviousYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    if (isNaN(year))
	{	window.alert("Please enter a valid 4 digit year.");
		top.newWin.frames['bottomCalFrame'].document.frmBotcalControl.Cancel.focus()
	    return false;
	}
	
	if (isFourDigitYear(year) && year > 1000) {
        year--;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE PREVIOUS MONTH AND REDRAW THE CALENDAR
function setPreviousMonth() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    
	if (isNaN(year))
	{
		window.alert("Please enter a valid 4 digit year.");
		top.newWin.frames['bottomCalFrame'].document.frmBotcalControl.Cancel.focus()
	    return false;
	}
	
	
	if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
        if (month == 0) {
            month = 11;
            if (year > 1000) {
                year--;
                calDate.setFullYear(year);
                top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
            }
        }
        else {
            month--;
        }
         calDate.setDate(1);
		 calDate.setMonth(month);
	
		var mdaysInMonth = getDaysInMonth()
		if(ClickedDay > mdaysInMonth)
			{ 
				calDate.setDate(mdaysInMonth);
				returnRelativeDate(mdaysInMonth);
			}
		else
			{	
				calDate.setDate(ClickedDay);
				returnRelativeDate(ClickedDay);
			}
		
        
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT MONTH AND REDRAW THE CALENDAR

function setNextMonth() {

    var year = top.newWin.frames['topCalFrame'].document.calControl.year.value;

   if(isNaN(year)) 
   {
   window.alert("Please enter a valid 4 digit year.");
   top.newWin.frames['bottomCalFrame'].document.frmBotcalControl.Cancel.focus()
   return false;
   }
	
    if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
        if (month == 11) {
            month = 0;
            year++;
            calDate.setFullYear(year);
            top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        }
        else {
            month++;
        }

      	
			
		calDate.setDate(1);
		calDate.setMonth(month);

		var mdaysInMonth = getDaysInMonth()
		if(ClickedDay > mdaysInMonth)
			{ 
				calDate.setDate(mdaysInMonth);
				returnRelativeDate(mdaysInMonth);
			}
		else
			{	
				calDate.setDate(ClickedDay);
				returnRelativeDate(ClickedDay);
			}
	     
			
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT YEAR AND REDRAW THE CALENDAR
function setNextYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    
	if (isNaN(year)) 
	{
	  window.alert("Please enter a valid 4 digit year.");
	  top.newWin.frames['bottomCalFrame'].document.frmBotcalControl.Cancel.focus()
	  return false;
	}
	
	
	if (isFourDigitYear(year)) {
        year++;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth()  {

    var days;
    var month = calDate.getMonth()+1;
    var year  = calDate.getFullYear();

    // RETURN 31 DAYS
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  {
        days=31;
    }
    // RETURN 30 DAYS
    else if (month==4 || month==6 || month==9 || month==11) {
        days=30;
    }
    // RETURN 29 DAYS
    else if (month==2)  {
        if (isLeapYear(year)) {
            days=29;
        }
        // RETURN 28 DAYS
        else {
            days=28;
        }
    }
    return (days);
}


// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isLeapYear (Year) {

    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}


// ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
function isFourDigitYear(year) {

    if (year.length != 4) {
	top.newWin.frames['topCalFrame'].document.calControl.year.value = calDate.getFullYear();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
    }
    else {
        return true;
    }
}


// BUILD THE MONTH SELECT LIST
function getMonthSelect() {

    monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
    
    // DETERMINE MONTH TO SET AS DEFAULT
    var activeMonth = calDate.getMonth();

    // START HTML SELECT LIST ELEMENT
    monthSelect = "<SELECT NAME='month' onChange='parent.opener.setCurrentMonth()'>";

    // LOOP THROUGH MONTH ARRAY
    for (i in monthArray) {
        
        // SHOW THE CORRECT MONTH IN THE SELECT LIST
        if (i == activeMonth) {
            monthSelect += "<OPTION SELECTED>" + monthArray[i] + "\n";
        }
        else {
            monthSelect += "<OPTION>" + monthArray[i] + "\n";
        }
    }
    monthSelect += "</SELECT>";

    // RETURN A STRING VALUE WHICH CONTAINS A SELECT LIST OF ALL 12 MONTHS
    return monthSelect;
}


// SET DAYS OF THE WEEK DEPENDING ON LANGUAGE
function createWeekdayList() {

        weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
        weekdayArray = new Array('Su','Mo','Tu','We','Th','Fr','Sa');

    // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
    var weekdays = "<TR width='500' BGCOLOR='" + headingCellColor + "'>";

    // LOOP THROUGH WEEKDAY ARRAY
    for (i in weekdayArray) {

        weekdays += "<TD class='heading' align=center>" + weekdayArray[i] + "</TD>";
    }
    weekdays += "</TR>";

    // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
    return weekdays;
}

function selectDate()
{	
   var sObjectString;
   var Selectedyear  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
   var Selectedmonth = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;   
    
   if (!(isNaN(Selectedyear)) && (Selectedyear.length ==4) && (isNumber(Selectedyear) == true)) {
	top.newWin.frames['topCalFrame'].document.calControl.year.value = Selectedyear;
   }else {
	window.alert("Please enter a valid 4 digit year.");
	top.newWin.frames['bottomCalFrame'].document.frmBotcalControl.Cancel.focus()
	return false;
   } 
	
	//***** add code Upendra
	strMonth = new Array('','01','02','03','04','05','06','07','08','09','10','11','12')
	
	// *** uppendra
   Selectedmonth = Selectedmonth + 1;
  // sDateString = Selectedmonth + "-" + calDay + "-" + Selectedyear; 
  
 	sDateString =  strMonth[Selectedmonth]+ "/" +calDay+ "/" + Selectedyear;


	
   if (MyDateField=="") MyDateField = sDateString;
		
		if((isIE)||((isNav)&&!(sLayerName))) {
			document.forms[sFormName][sControlName].value = MyDateField;
		}
		if((isNav)&&(!(sLayerName)==false)){
			document.layers[sLayerName].document.forms[sFormName][sControlName].value = MyDateField;
		}
  
   	sDateString = "";
	MyDateField = "";
	wherecamefrom= "";
	calDateField.focus;
	top.newWin.close();
	if(isIE) document.body.style.cursor = "default";
}

function cancel()
{
	var Enteredyear  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

	top.newWin.frames['topCalFrame'].document.calControl.year.value  = Enteredyear;
	
	sDateString = "";
	MyDateField = "";
	wherecamefrom= "";
	
	calDateField.focus;
	top.newWin.close();
}

// PRE-BUILD PORTIONS OF THE CALENDAR (FOR PERFORMANCE REASONS)
function buildCalParts() {

	// --NILANTHAJ AMMENDED THIS FUNCTION ON 16-FEB-2001
	//   TO ENCANCE FEATURES.--
    // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
    weekdays = createWeekdayList();

    // BUILD THE BLANK CELL ROWS
    blankCell = "<TD align=center bgcolor='" + cellColor + "'>&nbsp;&nbsp;&nbsp;</TD>";

    // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
    calendarBegin =
        "<HTML>" +
        "<HEAD>" +
        // STYLESHEET DEFINES APPEARANCE OF CALENDAR
        "<STYLE type='text/css'>" +
        "<!--" +
        "TD.heading { text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "; }" +
        "A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.focusDay:active { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
		"A.focusDay:visited { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
		"A.weekday:link { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
		"A.weekday:active { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
		"A.weekday:visited { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" +
        "-->" +
        "</STYLE>" +
        "</HEAD>" +
        "<BODY BGCOLOR='" + bottomBackground + "' topmargin='0' bottommargin='0'>" +
        "<CENTER>";

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
        if (isNav) {
            calendarBegin += 
                "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'><TR><TD>";
        }

        // BUILD WEEKDAY HEADINGS
        calendarBegin +=
            "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'>" +
            weekdays +
            "<TR>";


    // BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
    calendarEnd = "";

        // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
        if (bottomBorder) {
            calendarEnd += "<TR></TR>";
        }

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
        if (isNav) {
            calendarEnd += "</TD></TR></TABLE>";
        }

        // END THE TABLE AND HTML DOCUMENT
		calendarEnd +=
		    "</TABLE>" +
		    "<FORM NAME='frmBotcalControl' Id='frmBotcalControl'>" +
			"<TABLE ALIGN='center' cellpadding='1'>"+
			"<TR>"+
			"<TD>"+
			"<INPUT " +
            "TYPE=BUTTON NAME='SelectDate' VALUE='&nbsp;Select&nbsp;' onClick='javascript:ValidateBeforeSelect()'>"+
			"</TD>"+
			"<TD>"+
			"<INPUT " +
            "TYPE=BUTTON NAME='Cancel' VALUE='&nbsp;Cancel&nbsp;' onClick='javascript:parent.opener.cancel()'>"+
			"</TD>"+
			"</TR>"+
			"</TABLE>"+
			"</FORM>" +
            "</CENTER>" +
            "<SCR" + "IPT LANGUAGE=javascript>\n" +
		    "<!-- \n" +	
		    "	if (navigator.appName == 'Netscape') {\n" +
		    "	    isNav = true;\n" +
		    "}else {\n" +
		    "    isIE = true;\n" +
		    "}\n" +
		    "function ValidateBeforeSelect(){\n" +
		    "	numYear1 = new Number();\n" +
			"	var TypedYear = parent.topCalFrame.document.calControl.year.value;\n" +
		    "	numYear1 = TypedYear;\n" +
		    "		if (!(isNaN(TypedYear)) && (TypedYear.length ==4) && (parent.topCalFrame.isNumber(TypedYear) == true) && (numYear1.valueOf()>= 1000)) {\n" +
			"			parent.topCalFrame.document.calControl.year.value = TypedYear;\n" +
			"			parent.opener.selectDate();\n" +
			"			if(isIE) document.body.style.cursor = 'default';\n" +
			"		}else {\n" +
			"			alert('Please enter a valid 4 digit year.');\n" +
			"			//document.frmBotcalControl.Cancel.focus();\n" +
			"			return false;" +
			"		}}\n" +
			"//-->\n" +	
			"</SC" + "RIPT>\n" +
            "</BODY>" +
            "</HTML>";
}


// REPLACE ALL INSTANCES OF find WITH replace
// inString: the string you want to convert
// find:     the value to search for
// replace:  the value to substitute
//
// usage:    jsReplace(inString, find, replace);
// example:  jsReplace("To be or not to be", "be", "ski");
//           result: "To ski or not to ski"
//
function jsReplace(inString, find, replace) {

    var outString = "";

    if (!inString) {
        return "";
    }

    // REPLACE ALL INSTANCES OF find WITH replace
    if (inString.indexOf(find) != -1) {
        // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
        t = inString.split(find);

        // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
        return (t.join(replace));
    }
    else {
        return inString;
    }
}


// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
function doNothing() {
}


// ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
function makeTwoDigit(inValue) {

    var numVal = parseInt(inValue, 10);

    // VALUE IS LESS THAN TWO DIGITS IN LENGTH
    if (numVal < 10) {

        // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
        return("0" + numVal);
    }
    else {
        return numVal;
    }
}


// SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
function returnDate(inDay)
{
	ClickedDay = inDay
	
    // inDay = THE DAY THE USER CLICKED ON
    calDate.setDate(inDay);

    // SET THE DATE RETURNED TO THE USER
    var day           = calDate.getDate();
    var month         = calDate.getMonth()+1;
    var year          = calDate.getFullYear();
    var monthString   = monthArray[calDate.getMonth()];
    var monthAbbrev   = monthString.substring(0,3);
    var weekday       = weekdayList[calDate.getDay()];
    var weekdayAbbrev = weekday.substring(0,3);

    outDate = calDateFormat;

	 
    // RETURN TWO DIGIT DAY
    if (calDateFormat.indexOf("DD") != -1) {
        day = makeTwoDigit(day);
        outDate = jsReplace(outDate, "DD", day);
    }
    // RETURN ONE OR TWO DIGIT DAY
    else if (calDateFormat.indexOf("dd") != -1) {
        outDate = jsReplace(outDate, "dd", day);
    }

    // RETURN TWO DIGIT MONTH
    if (calDateFormat.indexOf("MM") != -1) {
        month = makeTwoDigit(month);
        outDate = jsReplace(outDate, "MM", month);
    }
    // RETURN ONE OR TWO DIGIT MONTH
    else if (calDateFormat.indexOf("mm") != -1) {
        outDate = jsReplace(outDate, "mm", month);
    }

    // RETURN FOUR-DIGIT YEAR
    if (calDateFormat.indexOf("yyyy") != -1) {
        outDate = jsReplace(outDate, "yyyy", year);
    }
    // RETURN TWO-DIGIT YEAR
    else if (calDateFormat.indexOf("yy") != -1) {
        var yearString = "" + year;
        var yearString = yearString.substring(2,4);
        outDate = jsReplace(outDate, "yy", yearString);
    
	}
    // RETURN FOUR-DIGIT YEAR
    else if (calDateFormat.indexOf("YY") != -1) {
        outDate = jsReplace(outDate, "YY", year);
    }

    // RETURN DAY OF MONTH (Initial Caps)
    if (calDateFormat.indexOf("Month") != -1) {
        outDate = jsReplace(outDate, "Month", monthString);
    }
    // RETURN DAY OF MONTH (lowercase letters)
    else if (calDateFormat.indexOf("month") != -1) {
        outDate = jsReplace(outDate, "month", monthString.toLowerCase());
    }
    // RETURN DAY OF MONTH (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MONTH") != -1) {
        outDate = jsReplace(outDate, "MONTH", monthString.toUpperCase());
    }

    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Mon") != -1) {
        outDate = jsReplace(outDate, "Mon", monthAbbrev);
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("mon") != -1) {
        outDate = jsReplace(outDate, "mon", monthAbbrev.toLowerCase());
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MON") != -1) {
        outDate = jsReplace(outDate, "MON", monthAbbrev.toUpperCase());
    }

    // RETURN WEEKDAY (Initial Caps)
    if (calDateFormat.indexOf("Weekday") != -1) {
        outDate = jsReplace(outDate, "Weekday", weekday);
    }
    // RETURN WEEKDAY (lowercase letters)
    else if (calDateFormat.indexOf("weekday") != -1) {
        outDate = jsReplace(outDate, "weekday", weekday.toLowerCase());
    }
    // RETURN WEEKDAY (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WEEKDAY") != -1) {
        outDate = jsReplace(outDate, "WEEKDAY", weekday.toUpperCase());
    }

    // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Wkdy") != -1) {
        outDate = jsReplace(outDate, "Wkdy", weekdayAbbrev);
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("wkdy") != -1) {
        outDate = jsReplace(outDate, "wkdy", weekdayAbbrev.toLowerCase());
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WKDY") != -1) {
        outDate = jsReplace(outDate, "WKDY", weekdayAbbrev.toUpperCase());
    }

    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
    //VA:Changed to achieve the selection on buttonclick
    MyDateField = outDate;
	 
    writeCalendar();
}

//======================================================
//' Method 		: returnRelativeDate
//' Purpose 	: To get the relative day when press the next previous month buttons or change the month combo box
//' Inputs 		: none
//' Returns 	: none
//' Created 	: 20-Aug-2001 - Upendra Prasad Haputantry
//' Modified 	:  
//======================================================
function returnRelativeDate(relativeInday)
{
	
    // relativeInday = THE DAY THE USER CLICKED ON
    calDate.setDate(relativeInday);

    // SET THE DATE RETURNED TO THE USER
    var day           = calDate.getDate();
    var month         = calDate.getMonth()+1;
    var year          = calDate.getFullYear();
    var monthString   = monthArray[calDate.getMonth()];
    var monthAbbrev   = monthString.substring(0,3);
    var weekday       = weekdayList[calDate.getDay()];
    var weekdayAbbrev = weekday.substring(0,3);

    outDate = calDateFormat;

    // RETURN TWO DIGIT DAY
    if (calDateFormat.indexOf("DD") != -1) {
        day = makeTwoDigit(day);
        outDate = jsReplace(outDate, "DD", day);
    }
    // RETURN ONE OR TWO DIGIT DAY
    else if (calDateFormat.indexOf("dd") != -1) {
        outDate = jsReplace(outDate, "dd", day);
    }

    // RETURN TWO DIGIT MONTH
    if (calDateFormat.indexOf("MM") != -1) {
        month = makeTwoDigit(month);
        outDate = jsReplace(outDate, "MM", month);
    }
    // RETURN ONE OR TWO DIGIT MONTH
    else if (calDateFormat.indexOf("mm") != -1) {
        outDate = jsReplace(outDate, "mm", month);
    }

    // RETURN FOUR-DIGIT YEAR
    if (calDateFormat.indexOf("yyyy") != -1) {
        outDate = jsReplace(outDate, "yyyy", year);
    }
    // RETURN TWO-DIGIT YEAR
    else if (calDateFormat.indexOf("yy") != -1) {
        var yearString = "" + year;
        var yearString = yearString.substring(2,4);
        outDate = jsReplace(outDate, "yy", yearString);
    
	}
    // RETURN FOUR-DIGIT YEAR
    else if (calDateFormat.indexOf("YY") != -1) {
        outDate = jsReplace(outDate, "YY", year);
    }

    // RETURN DAY OF MONTH (Initial Caps)
    if (calDateFormat.indexOf("Month") != -1) {
        outDate = jsReplace(outDate, "Month", monthString);
    }
    // RETURN DAY OF MONTH (lowercase letters)
    else if (calDateFormat.indexOf("month") != -1) {
        outDate = jsReplace(outDate, "month", monthString.toLowerCase());
    }
    // RETURN DAY OF MONTH (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MONTH") != -1) {
        outDate = jsReplace(outDate, "MONTH", monthString.toUpperCase());
    }

    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Mon") != -1) {
        outDate = jsReplace(outDate, "Mon", monthAbbrev);
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("mon") != -1) {
        outDate = jsReplace(outDate, "mon", monthAbbrev.toLowerCase());
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MON") != -1) {
        outDate = jsReplace(outDate, "MON", monthAbbrev.toUpperCase());
    }

    // RETURN WEEKDAY (Initial Caps)
    if (calDateFormat.indexOf("Weekday") != -1) {
        outDate = jsReplace(outDate, "Weekday", weekday);
    }
    // RETURN WEEKDAY (lowercase letters)
    else if (calDateFormat.indexOf("weekday") != -1) {
        outDate = jsReplace(outDate, "weekday", weekday.toLowerCase());
    }
    // RETURN WEEKDAY (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WEEKDAY") != -1) {
        outDate = jsReplace(outDate, "WEEKDAY", weekday.toUpperCase());
    }

    // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Wkdy") != -1) {
        outDate = jsReplace(outDate, "Wkdy", weekdayAbbrev);
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("wkdy") != -1) {
        outDate = jsReplace(outDate, "wkdy", weekdayAbbrev.toLowerCase());
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WKDY") != -1) {
        outDate = jsReplace(outDate, "WKDY", weekdayAbbrev.toUpperCase());
    }

    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
    //VA:Changed to achieve the selection on buttonclick
	
	
    MyDateField = outDate;
	  
   // writeCalendar();
}


//======================================================
//' Method 		: setFocus
//' Purpose 	: To keep the calendar always on top
//' Inputs 		: none
//' Returns 	: none
//' Created 	: 27-Aug-2001 - Upendra Prasad Haputantry
//' Modified 	:  20-sep-2001 - Upendra Prasad Haputantry
//======================================================
function setFocus()
{	if(window.parent.top.newWin!=null)
	{
		try{
		if (!window.parent.top.newWin.closed)
			window.parent.top.newWin.focus();
		}catch(exception){}
		
		
	}
}

function setCustomDate(){
	
var MINUTE = 60 * 1000
var HOUR = MINUTE * 60
var DAY = HOUR * 24
var WEEK = DAY * 7
var today = (new Date()).getTime()
var MonthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var startDay_of_CurrentWeek;
var startDay_of_PreviousWeek;
var endDay_of_Month= new Date(); 
var currentDay = (new Date()).getDay();
var currentMonth = (new Date()).getMonth();	
var year  = (new Date().getYear());

 
if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 1){
		
	document.MainForm.txtFromDate.value= MonthArray[(new Date()).getMonth()]+"-"+(new Date()).getDate()+"-"+year;;
	document.MainForm.txtToDate.value= MonthArray[(new Date()).getMonth()]+"-"+(new Date()).getDate()+"-"+year;
	}


if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 2){
	
	Yesterday = new Date(today - (DAY)) 
	
	document.MainForm.txtFromDate.value= MonthArray[Yesterday.getMonth()]+"-"+Yesterday.getDate()+"-"+year;;
	document.MainForm.txtToDate.value= MonthArray[Yesterday.getMonth()]+"-"+Yesterday.getDate()+"-"+year;
	}
	
if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 3){
		
		if (currentDay == 0)
		{
		startDay_of_CurrentWeek = new Date(today - (DAY)*7)
		endDate_of_CurrentWeek = new Date(today + (DAY))
		}
		else if(currentDay == 1) {
			startDay_of_CurrentWeek = new Date(today)
			endDate_of_CurrentWeek = new Date(today + (DAY)*6)
		
		}
		else if(currentDay == 2) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*1)
			endDate_of_CurrentWeek = new Date(today + (DAY)*5)
		}
		else if(currentDay == 3) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*2)
			endDate_of_CurrentWeek = new Date(today + (DAY)*4)
		
		}
		else if(currentDay == 4) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*3)
			endDate_of_CurrentWeek = new Date(today + (DAY)*3)
		
		}
		else if(currentDay == 5) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*4)
			endDate_of_CurrentWeek = new Date(today + (DAY)*2)
		
		}
		else if(currentDay == 6) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*5)
			endDate_of_CurrentWeek = new Date(today + (DAY)*1)
		
		}
		else if(currentDay == 7) {
			startDay_of_CurrentWeek = new Date(today - (DAY)*6)
			endDate_of_CurrentWeek = new Date(today)
		}
			
		document.MainForm.txtFromDate.value= MonthArray[startDay_of_CurrentWeek.getMonth()]+"-"+(startDay_of_CurrentWeek.getDate())+"-"+year;
		document.MainForm.txtToDate.value= MonthArray[endDate_of_CurrentWeek.getMonth()]+"-"+endDate_of_CurrentWeek.getDate()+"-"+year;
	}


if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 4)
{
		if (currentDay == 0){
			startDay_of_PreviousWeek = new Date(today - (DAY)*14)
			endDay_of_PreviousWeek = new Date(today - (DAY)*7)
		}else if(currentDay == 1) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*7)
			endDay_of_PreviousWeek = new Date(today - (DAY)*1)
		
		}else if(currentDay == 2) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*8)
			endDay_of_PreviousWeek = new Date(today - (DAY)*2)
		
		}else if(currentDay == 3) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*9)
			endDay_of_PreviousWeek = new Date(today - (DAY)*3)
		
		}else if(currentDay == 4) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*10)
			endDay_of_PreviousWeek = new Date(today - (DAY)*4)
		
		}else if(currentDay == 5) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*11)
			endDay_of_PreviousWeek = new Date(today - (DAY)*5)
		
		}else if(currentDay == 6) {
			startDay_of_PreviousWeek = new Date(today - (DAY)*12)
			endDay_of_PreviousWeek = new Date(today - (DAY)*6)
		}
		
    document.MainForm.txtFromDate.value= MonthArray[startDay_of_PreviousWeek.getMonth()]+"-"+(startDay_of_PreviousWeek.getDate())+"-"+year;
	document.MainForm.txtToDate.value= MonthArray[endDay_of_PreviousWeek.getMonth()]+"-"+endDay_of_PreviousWeek.getDate()+"-"+year;



	}



if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 5)
{	
	var endDate_of_CurrentMonth= CalMonthEnd(currentMonth); 	
	var year  = (new Date()).getYear();
		
	document.MainForm.txtToDate.value= MonthArray[currentMonth] +"-"+endDate_of_CurrentMonth+"-"+year;
	document.MainForm.txtFromDate.value= MonthArray[currentMonth]+"-01-"+year;
	}

	
	
if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 6)
{ 
	var year  = (new Date()).getYear(); 
	var PreviousMonth = currentMonth - 1  // previous month
	var endDate_of_PreviousMonth = CalMonthEnd(PreviousMonth);

	document.MainForm.txtToDate.value= MonthArray[PreviousMonth] +"-"+endDate_of_PreviousMonth+"-"+year;
	document.MainForm.txtFromDate.value= MonthArray[PreviousMonth] +"-01-"+year;
	}
	

	if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 7)
{
	
	var year  = (new Date()).getYear(); 
	var PreviousMonth = currentMonth - 3  // previous month
	var endDate_of_PreviousMonth = CalMonthEnd(PreviousMonth+2);

	document.MainForm.txtFromDate.value= MonthArray[PreviousMonth] +"-01-"+year;
	document.MainForm.txtToDate.value= MonthArray[PreviousMonth+2] +"-"+endDate_of_PreviousMonth+"-"+year;
	}
	
			
	if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 8)
{
	var year  = (new Date()).getYear(); 
	var PreviousMonth = currentMonth - 6  // previous month
	var endDate_of_PreviousMonth = CalMonthEnd(PreviousMonth+5);

	document.MainForm.txtFromDate.value= MonthArray[PreviousMonth] +"-01-"+year;
	document.MainForm.txtToDate.value= MonthArray[PreviousMonth+5] +"-"+endDate_of_PreviousMonth+"-"+year;

	}

	if (document.MainForm.dateSelect.options[document.MainForm.dateSelect.selectedIndex].value== 9)
{
	var year  = (new Date()).getYear(); 
	var PreviousMonth = currentMonth  // previous month
	var endDate_of_PreviousMonth = CalMonthEnd(PreviousMonth-1);

	document.MainForm.txtFromDate.value= MonthArray[PreviousMonth] +"-01-"+(year-1);
	document.MainForm.txtToDate.value= MonthArray[PreviousMonth-1] +"-"+endDate_of_PreviousMonth+"-"+year;

	}
	

function CalMonthEnd(month){
	
	if (month==0 || month==2 || month==4 || month==6 || month==7 ||
        month==9 || month==11)  {
        end_of_Month=31;
    }
	 else if (month==3 || month==5 || month==8 || month==10) {
        end_of_Month=30;
    }
     //RETURN 29 DAYS
    else if (month==1)  {
        if (isLeapYear(year)) {
            end_of_Month=29;
        }
        // RETURN 28 DAYS
        else {
            end_of_Month=28;
        }
    }
	return end_of_Month;
	}




}
//-->